package com.zero.manage.web.components.query;

import cn.hutool.core.util.StrUtil;
import com.querydsl.core.types.ExpressionUtils;
import com.querydsl.core.types.Order;
import com.querydsl.core.types.Predicate;
import com.zero.manage.web.components.base.BaseQuery;
import com.zero.manage.web.components.entity.QSysDictEntity;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Getter;
import lombok.Setter;

import java.util.LinkedHashMap;

/**
 * @author zero
 */
@Getter
@Setter
@ApiModel("系统字典-查询条件")
public class SysDictQuery extends BaseQuery {

    @ApiModelProperty("编码")
    private String code;

    @ApiModelProperty("备注")
    private String remarks;

    @Override
    public Predicate predicate() {
        QSysDictEntity qSysDictEntity = QSysDictEntity.sysDictEntity;
        Predicate predicate = super.predicate();
        //执行动态条件拼装
        predicate = StrUtil.isBlank(code) ? predicate : ExpressionUtils.and(predicate, qSysDictEntity.code.contains(code));
        predicate = StrUtil.isBlank(remarks) ? predicate : ExpressionUtils.and(predicate, qSysDictEntity.remarks.contains(remarks));
        return predicate;
    }

    @Override
    protected LinkedHashMap<String, String> initSort() {
        LinkedHashMap<String, String> map = new LinkedHashMap<>(1);
        map.put("createTime", Order.DESC.name());
        return map;
    }

}


